# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load(
    "//bazel:ui.bzl",
    "pl_deps_licenses",
    "pl_ui_test",
    "pl_webpack_deps",
    "pl_webpack_library",
)

package(default_visibility = ["//src:__subpackages__"])

UI_DEP_PACKAGES = [
    "yarn.lock",
    "package.json",
    ".babelrc.json",
    ".yarnrc.yml",
] + glob([
    ".yarn/patches/**",
    ".yarn/plugins/**",
    ".yarn/releases/**",
    ".yarn/sdks/**",
    ".yarn/versions/**",
])

UI_SRCS = glob([
    "*.js",
    "*.json",
    "assets/**",
    "src/**",
])

LICENSES_SRCS = [
    "tools/licenses/yarn_license_extractor.js",
]

pl_webpack_deps(
    name = "ui_deps",
    srcs = UI_DEP_PACKAGES,
    tags = ["no-remote-exec"],
)

pl_webpack_library(
    name = "ui_bundle",
    srcs = UI_SRCS,
    licenses = "//tools/licenses:all_licenses",
    stamp = select({
        "//bazel:stamped": True,
        "//conditions:default": False,
    }),
    tags = ["no-remote-exec"],
    deps = ":ui_deps",
)

pl_ui_test(
    name = "ui_tests",
    srcs = UI_SRCS,
    tags = ["no-remote-exec"],
    deps = ":ui_deps",
)

pl_deps_licenses(
    name = "npm_licenses",
    srcs = UI_DEP_PACKAGES + LICENSES_SRCS,
    tags = ["no-remote-exec"],
    # TODO(PP-2567): This is used by tools/licenses.
    # Move that into source and remove this.
    visibility = ["//visibility:public"],
    deps = ":ui_deps",
)
